package org.study.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.study.dao.IUserDaoRedis;
import org.study.dao.UserMapper;
import org.study.entity.User;
import org.study.service.IUserService;

/**
 * @author 627266
 * @version 2016年11月22日 下午4:50:37
 * @comment
 */
@Service
public class UserService implements IUserService {
	@Autowired
	UserMapper userMapper;

	@Autowired
	IUserDaoRedis userDaoReids;

	@Cacheable(value = "findList", keyGenerator = "wiselyKeyGenerator")
	@Override
	public List<User> findList() {
		return userMapper.findList();
	}

	@Cacheable(value = "selectByPrimaryKey", keyGenerator = "wiselyKeyGenerator")
	@Override
	public User selectByPrimaryKey(Long id) {
		return userMapper.selectByPrimaryKey(id);
	}

	@Cacheable(value = "selectByUser",keyGenerator = "wiselyKeyGenerator")
	@Override
	public User selectByUser(User user) {
		return userMapper.selectByPrimaryKey(user.getId());
	}

	@CacheEvict(allEntries = true, value = { "findList", "selectByPrimaryKey" })
	@Override
	public void deleteByPrimaryKey(Long id) {
		userMapper.deleteByPrimaryKey(id);
	}

	@Override
	public void saveUserByRedis(User user) {
		userDaoReids.saveUser(user);
	}

	@Override
	public User getUserByRedis(Long key) {
		return userDaoReids.getUser(key);
	}

}
